package com.ruoyi.user.controller.crm;


import com.ruoyi.common.core.constant.constant.PathConstant;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.pojo.result.Pages;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.user.model.pojo.entity.User;
import com.ruoyi.user.model.pojo.request.crm.CrmBannedUserRequest;
import com.ruoyi.user.model.pojo.request.crm.CrmSearchUserRequest;
import com.ruoyi.user.model.pojo.result.crm.CrmUserInfoResult;
import com.ruoyi.user.service.IUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


@Tag(name = "CRM-用户相关", description = "CRM-用户相关")
@RestController
@RequestMapping(PathConstant.CRM_PATH + "user")
public class CrmUserController {
    @Autowired
    private IUserService iUserService;


    @RequiresPermissions("system:appUser:list")
    @Operation(summary = "列表", description = "列表")
    @GetMapping("listPage")
    public R listPage(@ParameterObject CrmSearchUserRequest request) {
        Pages<CrmUserInfoResult> pages = iUserService.listPage(request);
        return R.ok(pages);
    }

    @RequiresPermissions("system:appUser:info")
    @Operation(summary = "详情", description = "详情")
    @GetMapping("/{id}")
    public R info(@PathVariable("id") Long id) {
        return R.ok(iUserService.getById(id));
    }

    @RequiresPermissions("system:appUser:edit")
    @Operation(summary = "编辑", description = "编辑")
    @PutMapping("/edit")
    public R edit(@RequestBody User user) {
        return R.ok(iUserService.updateById(user));
    }

    @RequiresPermissions("system:appUser:delete")
    @Operation(summary = "删除", description = "删除")
    @DeleteMapping("/{id}")
    public R edit(@PathVariable("id") Long id) {
        return R.ok(iUserService.removeById(id));
    }

    @RequiresPermissions("system:appUser:banned")
    @Operation(summary = "封禁/解除封禁", description = "封禁/解除封禁")
    @PostMapping("banned")
    public R banned(@RequestBody @Validated CrmBannedUserRequest request) {
        return R.ok(iUserService.forbiddenAndrelieve(request.getId(), request.getStatus()));
    }



}

